< previous page page_652 next page >

Page 652
methods. Transaction management using the SQL pass-through method with back-end databases also is covered.
By the time you complete this chapter, you'll be able to add transaction management to your Visual Basic applications, and you'll understand using cascading updates and deletes to maintain the referential integrity of your database. You also will know how to perform database-level, table-level, and page-level locking schemes in your database applications.
Database Locking Schemes
Whenever more than one person is accessing a single database, some type of process must be used to prevent two users from attempting to update the same record at the same time. This process is a locking scheme. In its simplest form, a locking scheme allows only one user at a time to update information in the database.
The Microsoft Jet database engine provides three levels of locking:
· Database locking: At this level, only one user at a time can access the database. Use this locking level when you need to perform work on multiple, related database objects (such as tables, queries, indexes, and relations) at the same time.
· Table locking: At this level, only one user at a time can access the locked table. Use this locking level when you need to perform work on multiple records in the same table.
· Page locking: At this level, only one user can access the page of records in the database table. This is the lowest locking level provided by Microsoft Jet. Page locking is handled automatically by Visual Basic whenever you attempt to edit or update a record in a dataset.
Database Locking
Database-level locking is the most restrictive locking scheme you can use in your Visual Basic application. When you open the database using the Visual Basic data control, you can lock the database by setting the Exclusive property of the data control to True. After you open the database by using Visual Basic code, you can lock the database by setting the second parameter of the OpenDatabase method to True. Here's an example:
Set db = DbEngine.OpenDatabase("c:mydb",True)
When the database is locked, no other users can open it. Other programs cannot read or write any information until you close the database. You should use database-level locking only when you must perform work that affects multiple data objects (such as tables, indexes, relations, and queries). The Visual Basic CompactDatabase operation, for example, affects all the data objects, so the database must be opened exclusively.

 
< previous page page_652 next page >

If you like this book, buy it!